#include <bits/stdc++.h>
using namespace std;
const int maxn=1002;

int n;
int a[maxn][maxn];
int record[maxn][maxn];

int sum(int i,int j)
{
	if(record[i][j]!=-1)
	{
		return record[i][j];
	}
	if(i==n)
	{
		//record[i][j]=a[i][j];
		return a[i][j];
	}
	else if(i<n)
	{
		record[i][j]=a[i][j]+max(sum(i+1,j),sum(i+1,j+1));
		return record[i][j];
	}
}

int main()
{
	memset(record,-1,sizeof(record));
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		cin >> a[i][j];
	}
	cout << sum(1,1) << endl;

	return 0;
}

